<template>
  <div id="app">
    <h1>{{msg}}</h1>
    <h1>{{$store.state.counter}}</h1>
    <button @click="handleAdd(10)">+</button>
    <button @click="handleSub(-10)">-</button>
    <button @click="asyncAdd(10)">异步++</button>
    <HelloVuex></HelloVuex>
  </div>
</template>

<script>
import HelloVuex from './components/HelloVuex'
export default {
  name: 'App',
  components: {
    HelloVuex
  },
  data () {
    return {
      msg: 'app组件'
    }
  },
  methods: {
    handleAdd (num) {
      this.$store.commit("ADD",num)
    },
    handleSub (num) {
      this.$store.commit({
        type: 'SUB',
        payload: {
          step: num,
        }
      })
    },
    asyncAdd (num) {
      this.$store.dispatch('asyncAdd',num)
    }
  }
  
}
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}

#nav {
  padding: 30px;
}

#nav a {
  font-weight: bold;
  color: #2c3e50;
}

#nav a.router-link-exact-active {
  color: #42b983;
}
</style>
